package com.compass.doctor.ui.message.viewmodel

import androidx.lifecycle.MutableLiveData
import com.compass.framework.model.Message
import com.compass.framework.toast.TipsToast
import com.compass.network.callback.IApiErrorCallback
import com.compass.network.manager.ApiManager
import com.compass.network.viewmodel.BaseViewModel

/**
 * Description：消息相关viewModel
 * Date:2023/12/7 14:50
 */
class MessageViewModel : BaseViewModel(){

     val messageLiveData: MutableLiveData<MutableList<Message>?> = MutableLiveData()
     val updateMessageLiveData: MutableLiveData<Boolean> = MutableLiveData()


    fun getNotificationMessage(count: Int, pageSize: Int = 10) {
        launchUIWithResult(responseBlock = {
            ApiManager.api.getNotificationMessage(count,pageSize)
        }, errorCall = object : IApiErrorCallback {
            override fun onError(code: Int?, error: String?) {
                TipsToast.showTips(error)
                messageLiveData.value =null
            }
        }, successBlock = {
            if (it == null || it.list.isNullOrEmpty()) {
                messageLiveData.value =null
            } else {
                messageLiveData.value = it.list
            }
        })

    }

    fun updateMessage(id: String) {
        launchUIWithResult(responseBlock = {
            ApiManager.api.updateMessage(id)
        }, errorCall = object : IApiErrorCallback {
            override fun onError(code: Int?, error: String?) {
                TipsToast.showTips(error)
                updateMessageLiveData.value=false
            }
        }, successBlock = {
            it?.let {
                updateMessageLiveData.value=true
            }?:kotlin.run {
                updateMessageLiveData.value=false
            }


        })

    }

}